package com.ITArmy.controller;

import com.ITArmy.beans.Focus;
import com.ITArmy.beans.Shows.FocusMessage;
import com.ITArmy.beans.Shows.UserFocus;
import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.ITArmy.service.FocusService;
import com.ITArmy.util.GetUserSession;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(value = "关注接口", tags = "关注接口")
@RequestMapping("/focus")
@Controller
public class FocusController extends BaseController {


    GetUserSession getUserSession = new GetUserSession();

    @RequestMapping("/addFocus")
    @ApiOperation(value = "用户关注作者", notes = "作者id", httpMethod = "POST", response = ServerResponse.class)
    @ResponseBody
    public ServerResponse addFocus(HttpServletRequest request, long authorId) {
        System.out.println("id为：" + authorId);
        return focusService.addFocus(request, authorId);
    }

    @RequestMapping("/cancelFocus")
    @ResponseBody
    @ApiOperation(value = "用户取消关注作者", notes = "需要两个数据，用户id和作者id", httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse cancelFocus(HttpServletRequest request, long authorId) {
        return focusService.cancelFocus(request, authorId);
    }

    @RequestMapping("/findFocusUser")
    @ApiOperation(value = "遍历用户关注的所有人", notes = "不需要任何的参数", httpMethod = "GET", response = String.class)
    public String findFocusUser(HttpServletRequest request, Model model) {
        getUserSession.addUserModel(request, model);
        model.addAttribute("users", focusService.findAllFocuses(request).getData());
        return "";
    }

    @RequestMapping("/findFuns")
    @ApiOperation(value = "获取用户粉丝", notes = "不需要任何的参数", httpMethod = "GET", response = String.class)
    public String findFuns(HttpServletRequest request, Model model) {
        getUserSession.addUserModel(request, model);
        model.addAttribute("funs", focusService.findFuns(request).getData());
        return "";
    }


    @RequestMapping("/focusInformation")
    @ApiOperation(value = "进入关注页面，显示已经关注的的人的信息，和推荐关注的作者", notes = "不需要任何的参数", httpMethod = "GET", response = String.class)
    public String focusInformation(HttpServletRequest request, Model model) {
        List<UserFocus> focusUsers = (List<UserFocus>) focusService.findAllFocuses(request).getData();
        //用户关注所有的人
        model.addAttribute("UserFocus", focusUsers);
        //用户点赞的所有的博客进行显示
        model.addAttribute("likeBlog", blogService.findLikeBlog(request));
        return "attention";
    }

//    @RequestMapping("/informationFocusPage")
//    @ApiOperation(value = "进入消息关注页面", httpMethod = "GET")
//    public String informationFocusPage(HttpServletRequest request, Model model) {
//        List<FocusMessage> focusMessages=messageService.getFocus(request);
//        model.addAttribute("focusMessages",focusMessages);
//        return "informationQuestion";
//    }

}
